/*
 * Created on Nov 12, 2003
 *
 * To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
package org.vectrics.common.gen;

import java.util.Vector;
import org.apache.log4j.Logger;
import org.vectrics.SystemException;
import org.vectrics.domain.Domain;
import org.vectrics.provider.CoreServiceLocator;
import org.vectrics.user.Person;

public class PersonNameGenerator {
	private transient static Logger log = Logger.getLogger(PersonNameGenerator.class);
	private Vector<String> firstNameList = new Vector<String>();
	private Vector<String> lastNameList = new Vector<String>();
	private Vector<String> middleNameList = new Vector<String>();

	public PersonNameGenerator() {
		super();
	}

	private void initRandomNames() {
		if (firstNameList.size() <= 0) {
			firstNameList.add("Arthur");
			firstNameList.add("Allen");			
			firstNameList.add("Bill");			
			firstNameList.add("Bob");
			firstNameList.add("Brad");
			firstNameList.add("Bruce");
			firstNameList.add("Barry");
			firstNameList.add("Baldwin");
			firstNameList.add("Bernard");			
			firstNameList.add("Bernie");			
			firstNameList.add("Carl");			
			firstNameList.add("Charles");			
			firstNameList.add("Chris");			
			firstNameList.add("Christian");			
			firstNameList.add("Christopher");			
			firstNameList.add("Craig");			
			firstNameList.add("Donald");			
			firstNameList.add("Don");			
			firstNameList.add("Edward");			
			firstNameList.add("Emmanual");			
			firstNameList.add("Evan");			
			firstNameList.add("Fred");			
			firstNameList.add("Frank");			
			firstNameList.add("Francis");			
			firstNameList.add("Greg");
			firstNameList.add("Gregory");			
			firstNameList.add("Gary");			
			firstNameList.add("Harold");			
			firstNameList.add("James");			
			firstNameList.add("Jack");			
			firstNameList.add("Jett");			
			firstNameList.add("Jordan");			
			firstNameList.add("James");			
			firstNameList.add("John");			
			firstNameList.add("Jordan");			
			firstNameList.add("Joshua");			
			firstNameList.add("Keith");			
			firstNameList.add("Lee");			
			firstNameList.add("Mike");			
			firstNameList.add("Michael");			
			firstNameList.add("Nicholas");			
			firstNameList.add("Nick");			
			firstNameList.add("Oscar");			
			firstNameList.add("Paul");			
			firstNameList.add("Ernie");			
			firstNameList.add("Richard");			
			firstNameList.add("Tony");			
			firstNameList.add("Patrick");			
			firstNameList.add("Scott");			
			firstNameList.add("Thomas");			
			firstNameList.add("Ralph");			
			firstNameList.add("Randy");			
			firstNameList.add("Richard");			
			firstNameList.add("Rick");			
			firstNameList.add("Ronald");			
			firstNameList.add("Ross");			
			firstNameList.add("Robert");			
			firstNameList.add("Roger");			
			firstNameList.add("Steve");			
			firstNameList.add("Tom");			
			firstNameList.add("Thomas");			
			firstNameList.add("Vinnie");			
			firstNameList.add("Vladimer");			
			firstNameList.add("Wally");			
			firstNameList.add("Walter");			
			firstNameList.add("William");			
			firstNameList.add("Wally");			
			firstNameList.add("Zern");			

			// Female
			firstNameList.add("Allison");			
			firstNameList.add("Amy");			
			firstNameList.add("Amber");			
			firstNameList.add("Bonnie");			
			firstNameList.add("Catherine");			
			firstNameList.add("Cathy");			
			firstNameList.add("Cassandra");			
			firstNameList.add("Christie");			
			firstNameList.add("Dawn");			
			firstNameList.add("Deborah");			
			firstNameList.add("Donna");			
			firstNameList.add("Doris");			
			firstNameList.add("Emily");			
			firstNameList.add("Gene");			
			firstNameList.add("Ingrid");			
			firstNameList.add("Eleanor");			
			firstNameList.add("Francine");			
			firstNameList.add("Nancy");			
			firstNameList.add("Ilana");			
			firstNameList.add("Janine");			
			firstNameList.add("Jeanette");			
			firstNameList.add("Jenifer");			
			firstNameList.add("Jill");			
			firstNameList.add("Jillian");			
			firstNameList.add("Kathy");			
			firstNameList.add("Karen");			
			firstNameList.add("Kim");			
			firstNameList.add("Kimberley");			
			firstNameList.add("Lisa");			
			firstNameList.add("Leslie");			
			firstNameList.add("Leanne");			
			firstNameList.add("Lina");			
			firstNameList.add("Laurie");			
			firstNameList.add("Lynn");			
			firstNameList.add("Laura");			
			firstNameList.add("Pauline");			
			firstNameList.add("Dawn");			
			firstNameList.add("Hanna");			
			firstNameList.add("Lauren");			
			firstNameList.add("Melissa");			
			firstNameList.add("Megan");			
			firstNameList.add("Marlene");			
			firstNameList.add("Nancy");			
			firstNameList.add("Ophelia");			
			firstNameList.add("Rachel");			
			firstNameList.add("Regina");			
			firstNameList.add("Rosa");			
			firstNameList.add("Rosemary");			
			firstNameList.add("Sandra");			
			firstNameList.add("Sarah");			
			firstNameList.add("Shannon");			
			firstNameList.add("Stacy");			
			firstNameList.add("Susan");			
			firstNameList.add("Theresa");			
			firstNameList.add("Tammy");			
			firstNameList.add("Tracy");			
			firstNameList.add("Valerie");			


			log.debug("Generate middlenames, create a good chance that the user's middlename will be blank");
			for (int i = 0; i < 20; i++) {
				middleNameList.add("");
			}			
			middleNameList.add("A.");			
			middleNameList.add("B.");			
			middleNameList.add("C.");			
			middleNameList.add("D.");			
			middleNameList.add("E.");			
			middleNameList.add("F.");			
			middleNameList.add("G.");			
			middleNameList.add("H.");			
			middleNameList.add("I.");
			middleNameList.add("J.");
			middleNameList.add("K.");
			middleNameList.add("L.");
			middleNameList.add("M.");
			middleNameList.add("N.");
			middleNameList.add("O.");
			middleNameList.add("P.");
			middleNameList.add("Q.");
			middleNameList.add("R.");
			middleNameList.add("S.");
			middleNameList.add("T.");
			middleNameList.add("U.");
			middleNameList.add("V.");
			middleNameList.add("W.");
			middleNameList.add("X.");
			middleNameList.add("Y.");
			middleNameList.add("Z.");
			
			lastNameList.add("Addey");			
			lastNameList.add("Agnus");			
			lastNameList.add("Ahearn");			
			lastNameList.add("Allen");
			lastNameList.add("Alverez");
			lastNameList.add("Anderson");
			lastNameList.add("Anthony");
			lastNameList.add("Anton");
			lastNameList.add("Aster");
			lastNameList.add("Aston");
			lastNameList.add("Baxter");
			lastNameList.add("Bennett");
			lastNameList.add("Brown");
			lastNameList.add("Benson");
			lastNameList.add("Braunbaum");
			lastNameList.add("Branch");
			lastNameList.add("Brown");
			lastNameList.add("Christy");
			lastNameList.add("Clawson");
			lastNameList.add("Clay");
			lastNameList.add("Clemons");
			lastNameList.add("Crasten");
			lastNameList.add("Callastrano");
			lastNameList.add("Cameron");
			lastNameList.add("Collins");
			lastNameList.add("Condin");
			lastNameList.add("Cranson");
			lastNameList.add("Darcy");
			lastNameList.add("Davidson");
			lastNameList.add("Ferguson");
			lastNameList.add("Ford");
			lastNameList.add("Franklin");
			lastNameList.add("Hanson");
			lastNameList.add("Hauschild");
			lastNameList.add("Gonstram");
			lastNameList.add("Guth");
			lastNameList.add("Hoelsken");
			lastNameList.add("Kummetz");
			lastNameList.add("Lamar");
			lastNameList.add("Leesan");
			lastNameList.add("Lewis");
			lastNameList.add("Linski");
			lastNameList.add("Lintner");
			lastNameList.add("Lowe");
			lastNameList.add("Lynch");
			lastNameList.add("Buck");
			lastNameList.add("Ferguson");			
			lastNameList.add("Freedman");
			lastNameList.add("Hardy");
			lastNameList.add("McKinney");
			lastNameList.add("North");
			lastNameList.add("Young");
			lastNameList.add("Fiest");
			lastNameList.add("Oglesby");
			lastNameList.add("Callahan");
			lastNameList.add("Carrier");
			lastNameList.add("Campton");
			lastNameList.add("Campton");
			lastNameList.add("Carlson");
			lastNameList.add("Carriscuspo");
			lastNameList.add("Coe");
			lastNameList.add("Copeland");
			lastNameList.add("Cooper");
			lastNameList.add("Cole");
			lastNameList.add("Cranson");
			lastNameList.add("Cranston");
			lastNameList.add("Dastion");
			lastNameList.add("Druerie");
			lastNameList.add("Edwards");
			lastNameList.add("Ellsworth");
			lastNameList.add("Franklin");
			lastNameList.add("Goodson");
			lastNameList.add("Hall");
			lastNameList.add("Harp");
			lastNameList.add("Haslet");
			lastNameList.add("Hayes");
			lastNameList.add("Haywood");
			lastNameList.add("Harwood");
			lastNameList.add("Handren");
			lastNameList.add("Harlen");
			lastNameList.add("Henderson");
			lastNameList.add("Hubble");
			lastNameList.add("Jammer");
			lastNameList.add("Jenner");
			lastNameList.add("Jenkins");
			lastNameList.add("Klein");
			lastNameList.add("Kremer");
			lastNameList.add("Mead");
			lastNameList.add("Meade");
			lastNameList.add("Mellwood");
			lastNameList.add("Mendsen");
			lastNameList.add("Merkin");
			lastNameList.add("Oak");
			lastNameList.add("Owens");
			lastNameList.add("Leesan");
			lastNameList.add("Ellis");
			lastNameList.add("Tummel");
			lastNameList.add("Macguire");
			lastNameList.add("Malvoleon");
			lastNameList.add("Miller");
			lastNameList.add("Leigh");
			lastNameList.add("List");
			lastNameList.add("Leyter");
			lastNameList.add("Lynge");
			lastNameList.add("King");
			lastNameList.add("Kingston");
			lastNameList.add("Klem");
			lastNameList.add("Nelson");
			lastNameList.add("Nelum");
			lastNameList.add("Neivers");
			lastNameList.add("Neal");
			lastNameList.add("Norquist");
			lastNameList.add("Norwood");
			lastNameList.add("Olsen");
			lastNameList.add("Oswald");
			lastNameList.add("Orvan");
			lastNameList.add("Osgan");
			lastNameList.add("Paul");
			lastNameList.add("Presser");
			lastNameList.add("Prosser");
			lastNameList.add("Prost");
			lastNameList.add("Plum");
			lastNameList.add("Plume");
			lastNameList.add("Plummer");
			lastNameList.add("Robinson");
			lastNameList.add("Skinner");
			lastNameList.add("Smitters");
			lastNameList.add("Smith");
			lastNameList.add("Slate");
			lastNameList.add("Slim");
			lastNameList.add("Slick");
			lastNameList.add("Ross");
			lastNameList.add("Collins");
			lastNameList.add("Richardson");
			lastNameList.add("Salzman");
			lastNameList.add("Scuuzmee");
			lastNameList.add("Strange");
			lastNameList.add("Stammers");
			lastNameList.add("Stillwater");
			lastNameList.add("Sweeney");
			lastNameList.add("Swanson");
			lastNameList.add("Herndon");
			lastNameList.add("Skaggs");
			lastNameList.add("Staley");
			lastNameList.add("Srivista");
			lastNameList.add("Susman");
			lastNameList.add("Tinner");
			lastNameList.add("Tanner");
			lastNameList.add("Walker");
			lastNameList.add("Weir");
			lastNameList.add("Welch");
			lastNameList.add("Winter");
			lastNameList.add("Wallace");
			lastNameList.add("Watchorn");
			lastNameList.add("White");
			lastNameList.add("Washington");
			lastNameList.add("White");
			lastNameList.add("Williams");
			lastNameList.add("Wilde");
			lastNameList.add("Will");
			lastNameList.add("Wilson");
			lastNameList.add("Yarborough");
			lastNameList.add("Zapen");
			lastNameList.add("Zimmerman");
			lastNameList.add("Zucker");
			
		}
	}
	public String createRandomUserName(Person person, Domain domain) {
		long suffix = 1;
		String userName = person.getFirstName().substring(0, 1) +  person.getLastName();// + suffix;
		userName = userName.toLowerCase();
		
		
		String newUserName = null; 
		Person otherPerson = CoreServiceLocator.getPersonService().findPersonWithUserName(domain, userName);
		while (otherPerson != null) {
			newUserName = userName + suffix; 
			
			otherPerson = CoreServiceLocator.getPersonService().findPersonWithUserName(domain, newUserName);
			suffix++;
		}
		
		
		if (newUserName != null)
			userName = newUserName;
		if (userName == null)
			throw new SystemException("User name is null");
		return(userName);
	}
	
	public void createRandomPerson(Person person) {
		initRandomNames();
		int numberOfTries = 0;
		int firstNameListSize = firstNameList.size();
		int lastNameListSize = lastNameList.size();
		int middleNameListSize = middleNameList.size();

		int firstIndex = (int)(Math.random() * firstNameListSize);		
		int middleIndex =  (int)(Math.random() * middleNameListSize);		
		int lastIndex =  (int)(Math.random() * lastNameListSize);
		log.debug("createRandomUsers() - Name Indices (first, middle, last) = (" 
				+ firstIndex + ", " 
				+ middleIndex + ", " + lastIndex + ")"); 

		String firstName = (String)firstNameList.elementAt(firstIndex);		
		String middleName = (String)middleNameList.elementAt(middleIndex);		
		String lastName = (String)lastNameList.elementAt(lastIndex);		

		
		person.setFirstName(firstName);
		person.setMiddleName(middleName);
		person.setLastName(lastName);
		numberOfTries++;
	}



}
